﻿@page "/gantt-chart/exporting"

@using Syncfusion.Blazor.Gantt
@using BlazorDemos
@using ej2_blazor_ganttdata

@inherits SampleBaseComponent;

<SampleDescription>
    <p>This sample demonstrates client-side exporting of the Gantt, which allows you to export Gantt data to Excel and CSV formats. Using the Gantt toolbar buttons, you can export Gantt data to the desired format.</p>
</SampleDescription>
<ActionDescription>
    <p>Gantt supports client-side exporting, which allows you to export its data to the Excel and CSV formats.</p>
    <p>In this demo, we have defined actions in the <code>ToolbarClick</code> event to export the Gantt data using the <code>ExcelExport</code> and <code>CsvExport</code> methods.</p>
</ActionDescription>

<div class="col-lg-12 control-section">
    <div class="content-wrapper">
        <div class="row">
            <SfGantt @ref="GanttObject" ID="GanttExport" DataSource="@TaskCollection" Height="450px" Width="100%" HighlightWeekends="true"
                     Toolbar="@(new List<string>(){ "ExcelExport", "CsvExport"})" AllowExcelExport="true"
                     AllowSelection="true" GridLines="GridLine.Both" TreeColumnIndex="1"
                     ProjectStartDate="@ProjectStart" ProjectEndDate="@ProjectEnd">
                <GanttTaskFields Id="TaskId" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Duration="Duration" Progress="Progress"
                                 Dependency="Predecessor" ParentID="ParentId"></GanttTaskFields>
                <GanttLabelSettings LeftLabel="TaskName" TValue="GanttData.TaskData">

                </GanttLabelSettings>
                <GanttSplitterSettings Position="30%"> </GanttSplitterSettings>
                <GanttEvents OnToolbarClick="ToolbarClickHandler" TValue=GanttData.TaskData></GanttEvents>
                <GanttTimelineSettings>
                    <GanttTopTierSettings Unit="TimelineViewMode.Week" Format="MMM dd, y"></GanttTopTierSettings>
                    <GanttBottomTierSettings Unit="TimelineViewMode.Day"></GanttBottomTierSettings>
                </GanttTimelineSettings>
            </SfGantt>
        </div>
    </div>
</div>

@code{
    public DateTime ProjectStart = new DateTime(2019, 3, 25);
    public DateTime ProjectEnd = new DateTime(2019, 7, 28);
    public List<GanttData.TaskData> TaskCollection { get; set; }

    public SfGantt<GanttData.TaskData> GanttObject;
    protected override void OnInitialized()
    {
        this.TaskCollection = GanttData.EditingData();

    }
    public void ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
    {
        if (args.Item.Id == "GanttExport_excelexport")
        {
            this.GanttObject.ExportToExcelAsync();
        }
        else if (args.Item.Id == "GanttExport_csvexport")
        {
            this.GanttObject.ExportToCsvAsync();
        }
    }
}